package com.groupbuying.sysconfig.dto.app;

import com.alibaba.fastjson.JSONObject;

/**
 * @Description 微信公众号数据格式化
 * @Author Davidbieber
 * @Email davidbieber@163.com
 * @Date 2019/10/25 9:08 上午
 */
public class DataFormatForWechatApp {

    public static JSONObject create(AppWechatInfo appWechatInfo){
        JSONObject jsonParams=new JSONObject();
        jsonParams.put("touser",appWechatInfo.getToUser().trim());//去除空格
        jsonParams.put("template_id",appWechatInfo.getTemplateId());
        jsonParams.put("url",appWechatInfo.getUrl());
        JSONObject dataJson=new JSONObject();
        for (AppDataInfo datum : appWechatInfo.getData()) {
            JSONObject dataTem = new JSONObject();
            dataTem.put("value", datum.getValue());
            dataTem.put("color",datum.getColor());
            dataJson.put(datum.getName(), dataTem);
        }
        JSONObject miniJson=new JSONObject();
        miniJson.put("appid","wxa4e726d2b82845d0");//商户端小程序appId
        miniJson.put("path",appWechatInfo.getMiniProgramInfo().getPagePath());
        jsonParams.put("miniprogram",miniJson);
        jsonParams.put("data",dataJson);

        return jsonParams;
    }
}
